using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;

public partial class Restricted_SurveysAvailable : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        this.Title = ConfigurationManager.AppSettings["SurveysAvailablePageTitle"];

        XmlDocument users = new XmlDocument();
        users.Load(ConfigurationManager.AppSettings["UsersLocation"]);
        XmlNodeList usersList = users.SelectNodes("Users/User");
        foreach (XmlNode user in usersList)
        {

            if (user.Attributes["username"].Value == User.Identity.Name)
            {
                if (user.Attributes["admin"].Value == "true")
                {
                    XmlDocument surveys = new XmlDocument();
                    surveys.Load(ConfigurationManager.AppSettings["SurveysLocation"]);
                    XmlNodeList surveyList = surveys.SelectNodes("Surveys/Survey");
                    foreach (XmlNode survey in surveyList)
                        GenerateLinks(survey.InnerXml);
                }
                else
                {
                    XmlNodeList surveyList = user.SelectNodes("Surveys/Survey");
                    foreach (XmlNode survey in surveyList)
                        GenerateLinks(survey.InnerXml);
                }
            }
        }
    }
    private void GenerateLinks(string queryStringParam)
    {

        HyperLink link = new HyperLink();
        link.Text = queryStringParam;
        link.NavigateUrl = "SurveyEdit.aspx?survey=" + queryStringParam;

        Literal lineBreak1 = new Literal();
        lineBreak1.Text = "<br/>";

        LinksPlaceHolder.Controls.Add(link);
        LinksPlaceHolder.Controls.Add(lineBreak1);
    }
    protected void LogoutButton_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
    }
}
